home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / INITPAL.C < prev    next >
Text File  |  1992-04-03  |  3KB  |  87 lines

  1. /* Sets up the palette in mode X, to a 2-2-2 general R-G-B organization, with
  2.    64 separate levels each of pure red, green, and blue. This is very good
  3.    for pure colors, but mediocre at best for mixes.
  4.  
  5.    -------------------------
  6.    |0  0 | Red|Green| Blue |
  7.    -------------------------
  8.     7  6  5  4  3  2  1  0
  9.  
  10.    -------------------------
  11.    |0  1 |      Red        |
  12.    -------------------------
  13.     7  6  5  4  3  2  1  0
  14.  
  15.    -------------------------
  16.    |1  0 |     Green       |
  17.    -------------------------
  18.     7  6  5  4  3  2  1  0
  19.  
  20.    -------------------------
  21.    |1  1 |      Blue       |
  22.    -------------------------
  23.     7  6  5  4  3  2  1  0
  24.  
  25.    Colors are gamma corrected for a gamma of 2.3 to provide approximately
  26.    even intensity steps on the screen.
  27. */
  28.  
  29. #include <dos.h>
  30. #include "polygon.h"
  31.  
  32. static unsigned char Gamma4Levels[] = { 0, 39, 53, 63 };
  33. static unsigned char Gamma64Levels[] = {
  34.     0, 10, 14, 17, 19, 21, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34,
  35.    35, 36, 37, 37, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46,
  36.    47, 48, 48, 49, 49, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55,
  37.    56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63,
  38. };
  39.  
  40. static unsigned char PaletteBlock[256][3];   /* 256 RGB entries */
  41.  
  42. void InitializePalette()
  43. {
  44.    int Red, Green, Blue, Index;
  45.    union REGS regset;
  46.    struct SREGS sregset;
  47.  
  48.    for (Red=0; Red<4; Red++) {
  49.       for (Green=0; Green<4; Green++) {
  50.          for (Blue=0; Blue<4; Blue++) {
  51.             Index = (Red<<4)+(Green<<2)+Blue;
  52.             PaletteBlock[Index][0] = Gamma4Levels[Red];
  53.             PaletteBlock[Index][1] = Gamma4Levels[Green];
  54.             PaletteBlock[Index][2] = Gamma4Levels[Blue];
  55.          }
  56.       }
  57.    }
  58.  
  59.    for (Red=0; Red<64; Red++) {
  60.       PaletteBlock[64+Red][0] = Gamma64Levels[Red];
  61.       PaletteBlock[64+Red][1] = 0;
  62.       PaletteBlock[64+Red][2] = 0;
  63.    }
  64.  
  65.    for (Green=0; Green<64; Green++) {
  66.       PaletteBlock[128+Green][0] = 0;
  67.       PaletteBlock[128+Green][1] = Gamma64Levels[Green];
  68.       PaletteBlock[128+Green][2] = 0;
  69.    }
  70.  
  71.    for (Blue=0; Blue<64; Blue++) {
  72.       PaletteBlock[192+Blue][0] = 0;
  73.       PaletteBlock[192+Blue][1] = 0;
  74.       PaletteBlock[192+Blue][2] = Gamma64Levels[Blue];
  75.    }
  76.  
  77.    /* Now set up the palette */
  78.    regset.x.ax = 0x1012;   /* set block of DAC registers function */
  79.    regset.x.bx = 0;        /* first DAC location to load */
  80.    regset.x.cx = 256;      /* # of DAC locations to load */
  81.    regset.x.dx = (unsigned int)PaletteBlock; /* offset of array from which
  82.                                                 to load RGB settings */
  83.    sregset.es = _DS; /* segment of array from which to load settings */
  84.    int86x(0x10, ®set, ®set, &sregset); /* load the palette block */
  85. }
  86.  
  87.